using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Input.Touch;


namespace GameForKids
{

    public class HelpScreen : DrawableGameComponent
    {
        public event EventHandler Clicked = delegate { };

        // hinh nen
        protected Texture2D Img;
        // noi dung
        protected String stringHelp;
        protected SpriteFont font;
        protected Rectangle rect;
        public bool show { get; set; }

        public void showhelp()
        {
            show = true;
        }

        public void hidehelp()
        {
            show = false;
        }
 
        public Point Location
        {
            get { return rect.Location; }
            set { rect.Location = value; }
        }


        public HelpScreen(Game game, string text) : base(game)
        {
            font = this.Game.Content.Load<SpriteFont>("Fonts/HelpFont");
            Img = this.Game.Content.Load<Texture2D>("Textures/Backgrounds/bg_help");
            stringHelp = text;
            rect = Img.Bounds;
            Location = new Point(75, -480);
            show = false;
        }

 

        public bool Contains(Point position)
        {
            return rect.Contains(position);
        }

 
        public bool Contains(Vector2 position)
        {
            return Contains(new Point((int)position.X, (int)position.Y));
        }


        public virtual void Draw(SpriteBatch spriteBatch)
        {

            if (show)
            {
                // hien
                if (rect.Y < 0)
                {
                    rect.Y += 40;
                    spriteBatch.Draw(Img, rect, Color.White);
                    spriteBatch.DrawString(font, stringHelp, new Vector2(rect.X + 50, rect.Y + 20), Color.Brown);
                }
                spriteBatch.Draw(Img, rect, Color.White);
                spriteBatch.DrawString(font, stringHelp, new Vector2(rect.X + 50, rect.Y + 20), Color.Brown);
            }
            else
            {
                //an
                if (rect.Y > -480)
                {
                    rect.Y -= 40;
                    spriteBatch.Draw(Img, rect, Color.White);
                    spriteBatch.DrawString(font, stringHelp, new Vector2(rect.X + 50, rect.Y + 20), Color.Brown);
                }
            }
        }


        public void TouchEvent(TouchLocation touch)
        {
            switch (touch.State)
            {
                case TouchLocationState.Pressed:
                    Pressed(touch);
                    break;
            }
        }


        public void Pressed(TouchLocation touch)
        {
            if (!show)
                return;
            if (Contains(touch.Position))
            {
                Clicked(this, new EventArgs());

            }
        }

       
    }
}
